IF EXISTS (
       SELECT *
       FROM   sys.objects
       WHERE  OBJECT_ID = OBJECT_ID(N'[dbo].[cms_sp_MediaFileSelectByFolderIds]')
              AND TYPE IN (N'P' ,N'PC')
   )
    DROP PROCEDURE [dbo].[cms_sp_MediaFileSelectByFolderIds]
GO

CREATE PROCEDURE [dbo].[cms_sp_MediaFileSelectByFolderIds] 
(@Ids NVARCHAR(500))
AS
BEGIN
	SELECT mf.MediaFileId
	      ,mf.SiteId
	      ,mf.SiteGroupId
	      ,mf.MimeTypeId
	      ,mt.MimeTypeName
	      ,mt.ContentType
	      ,mt.IsImage
	      ,mf.OriginalFileName
	      ,mf.LinkedFileName
	      ,mf.Height
	      ,mf.Width
	      ,mf.FileSize
	      ,mf.CreatedBy
	      ,mf.DateCreated
	      ,mf.LastUpdatedBy
	      ,mf.DateLastUpdated
	      ,mc.BlockFromSearchEngines
	FROM   Media m
	       JOIN MediaContents mc
	            ON  mc.MediaId = m.MediaId
	       JOIN MediaContentFileLinks mcfl
	            ON  mcfl.MediaContentId = mc.MediaContentId
	       JOIN MediaFiles mf
	            ON  mf.MediaFileId = mcfl.MediaFileId
	       JOIN MimeTypes mt
	            ON  mt.MimeTypeId = mf.MimeTypeId
	WHERE  m.MediaId IN (SELECT cusi.integer
	                     FROM   dbo.cms_udf_SplitIntegers(@Ids) cusi)
END
GO